import { getWebCastUrl } from '../../api/webCast';

Component({
  /**
   * 组件的属性列表
   */
  properties: {
    allowSignup:{
      type: Boolean,
      value: false
    },
    enrolled: {
      type: Boolean,
      value: false
    },
    isLive: {
      type: Boolean,
      value: false
    },
    liveStart: {
      type: Boolean,
      value: false
    },
    activityId: {
      type: String,
      value: ''
    },
    isCurrent: {
      type: Boolean,
      value: false
    }
  },

  options: {
    styleIsolation: "share"
  },

  /**
   * 组件的初始数据
   */
  data: {
    showDialog: false,
    link: ''
  },

  /**
   * 组件的方法列表
   */
  methods: {
    onClickEnroll(){
      this.triggerEvent('enroll')
    },

    toLiving() {
      if (!getApp().globalData.token) {
        wx.showToast({
          title:'请先登录',
          icon: 'none'
        })
      } else {
        wx.getSystemInfo({
          success: (result) => {
            const platform = result.platform.toLocaleLowerCase();
            if (platform.indexOf('ios') > -1 || platform.indexOf('devtools') > -1) {
              getWebCastUrl(this.data.activityId).then(res => {
                this.setData({
                  link: res,
                  showDialog: true
                })
              })
            } else if (platform.indexOf('android') > -1){
              wx.navigateTo({
                url: '/packageA/pages/living/living?activityId=' + this.data.activityId
              })
            }
          }
        })
      }
    },

    consult() {
      this.triggerEvent('consult')
    },

    confirmCopy() {
      const _this = this;
      wx.setClipboardData({
        data: _this.data.link,
        success: function (res) {
          _this.setData({ showDialog: false });
          wx.showToast({ title: '复制成功' });
        }
      })
    },

    closeDialog() {
      this.setData({ showDialog: false });
    }
  }
})
